package com.ciwong.epaper.modules.epaper.ui.newlistenspeak;

import android.app.Activity;
import android.content.Context;
import android.text.Html;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.ciwong.epaper.R;
import com.ciwong.epaper.modules.dbbean.AnswerContent;
import com.ciwong.epaper.modules.epaper.bean.Attachments;
import com.ciwong.epaper.modules.epaper.bean.ModuleSet;
import com.ciwong.epaper.modules.epaper.bean.OptionDetail;
import com.ciwong.epaper.modules.epaper.bean.OptionInfo;
import com.ciwong.epaper.modules.epaper.bean.Questions;
import com.ciwong.epaper.modules.epaper.bean.ResourceDetail;
import com.ciwong.epaper.modules.epaper.util.ListenSpeakUtil;
import com.ciwong.epaper.util.ESystem;
import com.ciwong.epaper.widget.ScaleScreenImageView;
import com.ciwong.libs.utils.CWLog;
import com.ciwong.libs.utils.DeviceUtils;
import com.ciwong.mobilelib.utils.BaseJumpManager;
import com.ciwong.mobilelib.utils.BaseUtils;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageSize;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/2/13.
 */
public class QuestionLayout extends LinearLayout {


    private final String TAG = "QuestionLayout";
    protected TextView tvTitle;// 问题标题
    private TextView tvBigStem;//大题标题
    private TextView tvChildStem;// 小题标题
    protected TextView tvAnswerCard;
    protected TextView tvStem;
    protected WebView tvSmallStem;
    protected LinearLayout imgContainer;
    protected LinearLayout optionsLayout;// 小题选项
    //用于上个选择的选项，选中新选项，旧选中选项复位--neo 2017/3/11
    protected View oldSelectedView = null;

    protected String[] optionHeads = new String[]{"A", "B", "C", "D", "E", "F",
            "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
            "T", "U", "V", "W", "X", "Y", "Z"};

    protected int checkedIndex = -1;

    protected OptionInfo checkedOptionInfo = null;// 用户选中的选项

    private boolean mAllowAnswer = true;


    private View bg_big_stem;
    private View bg_question_content;

    private View root_question_layout;

    public QuestionLayout(Context context) {
        super(context);
        LayoutInflater.from(this.getContext()).inflate(R.layout.listen_speak_question_layout, this);
        initView();
    }

    public QuestionLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        LayoutInflater.from(this.getContext()).inflate(R.layout.listen_speak_question_layout, this);
        initView();
    }

    public QuestionLayout(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        LayoutInflater.from(this.getContext()).inflate(R.layout.listen_speak_question_layout, this);
        initView();
    }

    private void initView() {
        tvTitle = (TextView) findViewById(R.id.question_title);// 问题标题
        tvAnswerCard = (TextView) findViewById(R.id.tv_answer_card);// 答题卡

        tvBigStem = (TextView) findViewById(R.id.big_question_stem);// 大题题干
        tvStem = (TextView) findViewById(R.id.small_question_stem_tv);// 小题题干

        tvSmallStem = (WebView) findViewById(R.id.small_question_stem);// 小题题干
        tvSmallStem.getSettings().setDefaultTextEncodingName("utf-8");
        tvSmallStem.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        tvSmallStem.setVerticalScrollBarEnabled(false);
        tvSmallStem.setVerticalScrollbarOverlay(false);
        tvSmallStem.setHorizontalScrollBarEnabled(false);
        tvSmallStem.setHorizontalScrollbarOverlay(false);
        tvSmallStem.setBackgroundColor(0);


        tvChildStem = (TextView) findViewById(R.id.child_quesion_stem);// 子题题干
        imgContainer = (LinearLayout) findViewById(R.id.img_container);
        optionsLayout = (LinearLayout) findViewById(R.id.question_options);// 小题选项

        bg_big_stem = findViewById(R.id.bg_big_stem);
        bg_question_content = findViewById(R.id.bg_question_content);

        root_question_layout = findViewById(R.id.root_question_layout);
//        将字体文件保存在assets/fonts/目录下，创建Typeface对象
//        Typeface typeFace = Typeface.createFromAsset(this.getContext().getAssets(), "fonts/xmlt.ttf");
//        使用字体
//        tvStem.setTypeface(typeFace);
    }


    /**
     * 考试开始预先加载大题和选项
     */
    public int initBigQuestionAndOptions(List<ResourceDetail> mResourceList, int bigQuesIndex, int smallQuesIndex, View seekBar) {
        ModuleSet moduleSet = mResourceList.get(bigQuesIndex)
                .getTemplateSettings();
        // 设置大题题干  切换问题标题
        setBigQuesStem(moduleSet.getContent(), bigQuesIndex, smallQuesIndex);

        // 取得小题列表
        List<Questions> smallQuesList = mResourceList.get(bigQuesIndex).getQuestions();
        int questionType = -1;

        if (smallQuesList != null && !smallQuesList.isEmpty()) {
            Questions smallQues = smallQuesList.get(smallQuesIndex);
            // 取得小题类型
            questionType = smallQues.getType();
            imgContainerRemoveAllViews();
            //模仿朗读
            if (questionType == Questions.QuestionType.QUESTION_TYPE_IMITATE_READ) {
                OptionDetail trunk = smallQues.getTrunk();
                //添加小题序号
                String textno;
                String textScore = ListenSpeakUtil.getChildQuestionScore(smallQues, mResourceList.get(bigQuesIndex).getScores());
                if (smallQues.getSort() != null && !"".equals(smallQues.getSort())) {
                    //textno = smallQues.getSort() + "、" + textScore + trunk.getBody();
                    //去除小题索引
                    textno = textScore + trunk.getBody();
                } else {
                    textno = trunk.getBody();
                    if(!"".equals(textno)){
                        if(!"".equals(textScore)){
                            StringBuffer stringBuffer = new StringBuffer(textno);
                            stringBuffer.insert(2, textScore);
                            textno = stringBuffer.toString();
                        }
                    }else{
                        textno = textScore;
                    }
                }
                //加载小题题干
                setSmallQuestionStem(textno);
                //开始加载图片
                startLoadImg(trunk, seekBar);

            } else {

                imgContainerSetVisibility(View.GONE);
                setSmallQuestionStem(null);

            }
        }

        return questionType;
    }

    /**
     * 设置大题题干内容
     *
     * @param text
     */
    public void setBigQuesStem(String text, int BigQuesIndex, int SmallQuesIndex) {
        changeQuestionTitle(BigQuesIndex, SmallQuesIndex);
        if (TextUtils.isEmpty(text)) {
            tvBigStem.setVisibility(View.GONE);
        } else {
            tvBigStem.setText(text);
            tvBigStem.setVisibility(View.VISIBLE);
        }
    }


    /**
     * 加载小题题干
     * 包括纯文本和富文本
     *
     * @param text
     */
    public void setSmallQuestionStem(String text) {
        if (TextUtils.isEmpty(text)) {
            //加载含有H5标题
            tvSmallStem.setVisibility(View.GONE);
            //加载纯文本标题
            tvStem.setVisibility(View.GONE);
        } else {
            if (text.contains("<table") || text.contains("<img") || text.contains("{#blank#}")) {
                String textValue = ListenSpeakUtil.addHtmlHead(text);
                tvSmallStem.loadDataWithBaseURL(null, textValue,
                        "text/html; charset=utf-8", "utf-8", null);
                tvSmallStem.setVisibility(View.VISIBLE);
                tvStem.setVisibility(View.GONE);
            } else {
                tvStem.setText(Html.fromHtml(ListenSpeakUtil.parseHtmlText2(text)));
                tvStem.setVisibility(View.VISIBLE);
                tvSmallStem.setVisibility(View.GONE);
            }
        }
    }


    /**
     * 加载子题题干
     * type=5 显示小题序号 小题提干
     *
     * @param text
     */
    public void setChildQuestionStem(String text, boolean isNewVersion) {
        if (TextUtils.isEmpty(text)) {
            tvChildStem.setVisibility(View.GONE);
        } else {
            if (!TextUtils.isEmpty(text)) {
                text = text.replace("\n", "<br>");
            }
            tvChildStem.setText(Html.fromHtml(text));
            tvChildStem.setVisibility(View.VISIBLE);
            if (isNewVersion) {// 新版的显示子题题干的时候要隐藏小题题干
                tvSmallStem.setVisibility(View.GONE);
                tvStem.setVisibility(View.GONE);
            }
        }
    }


    /**
     * 切换问题标题
     */
    public void changeQuestionTitle(int BigQuesIndex, int SmallQuesIndex) {
        tvTitle.setText(getContext().getString(R.string.question_title, BaseUtils.formatInteger(BigQuesIndex + 1), String.valueOf(SmallQuesIndex + 1)));
    }

    public void setTitleVisibility(int visibility) {
        tvTitle.setVisibility(visibility);
    }

    /**
     * 显示总时间
     *
     * @param timeStr
     */
    public void setShowTotalTime(String timeStr) {
        tvAnswerCard.setText(timeStr);
    }

    public void setAnswerCardOnClickListener(OnClickListener listener) {
        tvAnswerCard.setVisibility(VISIBLE);
        tvAnswerCard.setOnClickListener(listener);
    }

    public void setAnswerCardOnLongClickListener(OnLongClickListener longClickListener) {
        tvAnswerCard.setOnLongClickListener(longClickListener);
    }

    /**
     * 显示图片
     *
     * @param imgUrl
     */
    public void showImg(final String imgUrl, final int index,
                        final List<String> imgList) {
        final ScaleScreenImageView itemImg = (ScaleScreenImageView) View
                .inflate(getContext(),
                        R.layout.item_listen_speak_img, null);
        itemImg.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                BaseJumpManager.jumpToScanImage((Activity) getContext(),
                        R.string.listen_speak, new ArrayList<String>(imgList),
                        index);
            }
        });
        ImageSize size = new ImageSize(DeviceUtils.getScreenWdith(),
                R.dimen.word_pic_height);
        if (itemImg != null) {
            itemImg.setImageBitmap(ImageLoader.getInstance().loadImageSync(imgUrl, size));
        }

        imgContainer.setVisibility(View.VISIBLE);
        imgContainer.addView(itemImg);

    }

    public void imgContainerRemoveAllViews() {
        imgContainer.removeAllViews();
    }

    public void imgContainerSetVisibility(int visibility) {
        imgContainer.setVisibility(visibility);
    }


    public void optionsLayoutRemoveAllViews() {
        optionsLayout.removeAllViews();
        optionsLayout.setVisibility(GONE);
    }

    boolean isMove = false;

    public void reSetCheckedIndex(int index) {
        checkedIndex = index;
    }

    /**
     * 加载选项布局
     *
     * @param optionInfoList
     */
    public OptionInfo loadOptionLayout(final List<OptionInfo> optionInfoList, final int mQuestionType) {
        optionsLayout.removeAllViews();

        oldSelectedView = null;
        checkedOptionInfo = null;

        //选择题  填空题
        if (mQuestionType == Questions.QuestionType.QUESTION_TYPE_CHOICE || mQuestionType == Questions.QuestionType.QUESTION_TYPE_FILL_BLANK) {
            int topBottom1 = DeviceUtils.dip2px(3);
            LayoutParams params1 = new LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params1.setMargins(0, topBottom1, 0, topBottom1);

            for (int i = 0; optionInfoList != null
                    && i < optionInfoList.size(); i++) {

                final OptionInfo optionInfo = optionInfoList.get(i);

                final View container = View.inflate(getContext(),
                        R.layout.item_listen_speak_view, null);

                final LinearLayout itemView = (LinearLayout) container
                        .findViewById(R.id.item_ls_view);

                final LinearLayout itemBody = (LinearLayout) View.inflate(getContext(),
                        R.layout.item_listen_speak_body, itemView);

                final TextView checkheader = (TextView) itemBody
                        .findViewById(R.id.item_left_btn);

                final EditText itemText = (EditText) itemBody
                        .findViewById(R.id.item_options_tv);

                final ImageView itemImg = (ImageView) itemBody
                        .findViewById(R.id.item_img);

                if (checkedIndex == i) {
                    container.setSelected(true);
                    checkheader.setSelected(true);
                    // itemText.setSelected(true);
                    oldSelectedView = container;
                } else {
                    container.setSelected(false);
                    checkheader.setSelected(false);
                    // itemText.setSelected(false);
                }

                final int index = i;
//                container.setEnabled(mQuestionType == Questions.QuestionType.QUESTION_TYPE_CHOICE);
                checkheader.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        container.performClick();
                    }
                });
                itemView.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        container.performClick();
                    }
                });
                itemText.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        container.performClick();
                    }
                });
                //选择题
                if (mQuestionType == Questions.QuestionType.QUESTION_TYPE_FILL_BLANK) {
                    itemText.setOnTouchListener(new OnTouchListener() {
                        @Override
                        public boolean onTouch(View v, MotionEvent event) {
                            switch (event.getAction()) {
                                case MotionEvent.ACTION_DOWN:
                                    isMove = false;
                                    break;
                                case MotionEvent.ACTION_MOVE:
                                    isMove = true;
                                    break;
                                case MotionEvent.ACTION_UP:
                                    if (!isMove) {
                                        container.performClick();
                                        isMove = false;
                                    }
                                    break;
                                default:
                                    break;
                            }
                            return false;
                        }
                    });
                }
                container.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {

//                        if (v.equals(oldSelectedView)) {
//                            return;
//                        }

                        //没有播放请开始答题的提示音之前不允许答题
//                        if (!mAllowAnswer) {
//                            return;
//                        }

                        if (oldSelectedView != null) {
                            oldSelectedView.setSelected(false);
                            checkheader.setSelected(false);
                            // itemText.setSelected(false);
                        }
                        checkedOptionInfo = optionInfo;

                        checkedIndex = index;
                        container.setSelected(true);
                        checkheader.setSelected(true);
                        // itemText.setSelected(true);
                        oldSelectedView = container;
                        //选择题
                        if (mQuestionType == Questions.QuestionType.QUESTION_TYPE_FILL_BLANK) {
                            InputMethodManager inputMethodManager = (InputMethodManager) itemText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                            itemText.setFocusable(true);
                            itemText.setFocusableInTouchMode(true);
                            itemText.requestFocus();
                            if (inputMethodManager != null) {
                                inputMethodManager.showSoftInput(itemText, 0);
                            }
                        }
                    }
                });

                if (optionInfo != null) {
                    List<OptionDetail> optionDetailList = optionInfo.getValue();
                    if (optionDetailList != null && !optionDetailList.isEmpty()) {
                        OptionDetail optionDetail = optionDetailList.get(0);
                        if (optionDetail != null
                                && optionDetail.getBody() != null) {
                            String body = optionDetail.getBody();
                            //选择题
                            if (mQuestionType == Questions.QuestionType.QUESTION_TYPE_CHOICE) {
                                checkheader.setText(optionHeads[i]);
                                if (!TextUtils.isEmpty(body)) {
                                    itemText.setText(body);
                                } else {
                                    itemText.setVisibility(View.GONE);
                                }
//                                itemText.setEnabled(false);
                                itemText.setFocusable(false);//失去焦点
                                itemText.setTextIsSelectable(false);//文字不可选
                                itemText.setCursorVisible(false);//不显示光标
                                itemText.setFocusableInTouchMode(false);
                            } else {
                                // 填空题
//                                itemText.setEnabled(false);
                                itemText.setFocusable(true);//失去焦点
                                itemText.setTextIsSelectable(true);//文字不可选
                                itemText.setCursorVisible(true);//不显示光标
                                itemText.setFocusableInTouchMode(true);
                                //填空题题号--neo
//                                 int questNumber=mQuesTotalIndex+ mBlankOffset;
                                if (optionInfo.getSort() != null && !"".equals(optionInfo.getSort())) {
                                    checkheader.setText(optionInfo.getSort());
                                } else {
                                    checkheader.setText(String.valueOf(i + 1));
                                }
                                checkheader.setTextColor(getResources()
                                        .getColor(R.color.default_text_color));

                                checkheader.setBackgroundColor(0);
                                itemText.setText("");
                                itemText.setTag(body);
                                itemText.setSingleLine();
                                itemText.setWidth(DeviceUtils.dip2px(200));

//                                mBlankOffset++;
                            }

                            // 加载附件里的图片
                            List<Attachments> attachmentList = optionDetail
                                    .getAttachments();
                            if (attachmentList != null
                                    && !attachmentList.isEmpty()) {
                                Attachments attachments = attachmentList.get(0);
                                final String url = attachments.getUrl();
                                if (!TextUtils.isEmpty(url)) {
                                    switch (attachments.getFileType()) {
                                        case Attachments.AttachmentFileType.ATTACHMENT_FILE_TYPE_IMG:// 图片
                                            itemImg.setOnClickListener(
                                                    new OnClickListener() {
                                                        @Override
                                                        public void onClick(
                                                                View v) {
                                                            ArrayList<String> urlList = new ArrayList<String>();
                                                            urlList.add(ESystem.formatPath(url));
                                                            BaseJumpManager.jumpToScanImage((Activity) getContext(), R.string.listen_speak, urlList, 0);
                                                        }
                                                    });
                                            ImageLoader.getInstance().displayImage(ESystem.formatPath(url), itemImg);
                                            itemImg.setVisibility(View.VISIBLE);
                                            break;
                                        case Attachments.AttachmentFileType.ATTACHMENT_FILE_TYPE_AUDIO:// 语音
                                            break;
                                    }
                                }

                            }

                            optionsLayout.setVisibility(VISIBLE);
                            optionsLayout.addView(container);
                            if (mQuestionType == Questions.QuestionType.QUESTION_TYPE_FILL_BLANK) {
                                container.findViewById(R.id.item_line2)
                                        .setVisibility(View.VISIBLE);
                              /*  if (i == optionInfoList.size() - 1) {
                                    container.findViewById(R.id.item_line2)
                                            .setVisibility(View.VISIBLE);
                                }*/
                            }


                        }
                    }
                }
            }
        }

        return checkedOptionInfo;
    }


    /**
     * 填空题作答时自动弹出软盘,开放答题
     */
    public void showSoftInput(boolean isShowSoft) {
//        optionsLayout.

        Log.d(TAG, "#######showSoftInput########");
        View child;
        int childCount = optionsLayout.getChildCount();

//        controlKeyboardLayout(root_question_layout,optionsLayout);

        for (int i = 0; i < childCount; i++) {
            child = optionsLayout.getChildAt(i);
            final EditText itemText = (EditText) child
                    .findViewById(R.id.item_options_tv);
//            itemText.setEnabled(true);
            itemText.setFocusable(true);//失去焦点
            itemText.setTextIsSelectable(true);//文字不可选
            itemText.setCursorVisible(true);//不显示光标
            itemText.setFocusableInTouchMode(true);
        }

        if (isShowSoft) {
            child = optionsLayout.getChildAt(0);
            if (child != null) {
                final EditText itemText = (EditText) child
                        .findViewById(R.id.item_options_tv);
                itemText.setEnabled(true);
                InputMethodManager inputMethodManager = (InputMethodManager) itemText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

                if (null != itemText && inputMethodManager != null) {
                    itemText.setFocusable(true);
                    itemText.setFocusableInTouchMode(true);
                    itemText.requestFocus();
                    if (inputMethodManager != null) {
                        Log.d(TAG, "#######inputMethodManager showSoftInput########");
                        inputMethodManager.showSoftInput(itemText, 0);
//                        inputMethodManager.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
                    }
                }

            }
        }

    }


    public LinearLayout getOptionsLayout() {
        return optionsLayout;
    }

    /**
     * 开始加载图片
     *
     * @param optionsDetail
     */
    public void startLoadImg(OptionDetail optionsDetail, View seekBar) {
        // 取附件集合
        final List<Attachments> attachmentsList = optionsDetail
                .getAttachments();
        List<String> imgUrlList = new ArrayList<String>();
        imgContainerRemoveAllViews();

        if (attachmentsList != null && !attachmentsList.isEmpty()) {
            for (int i = 0; i < attachmentsList.size(); i++) {
                Attachments attachments = attachmentsList.get(i);
                if (attachments != null) {
                    String url = attachments.getUrl();
                    if (!TextUtils.isEmpty(url)) {
                        switch (attachments.getFileType()) {
                            case Attachments.AttachmentFileType.ATTACHMENT_FILE_TYPE_IMG:// 图片
                                if (i == 0) {
                                    seekBar.setVisibility(View.GONE);
                                    imgContainerSetVisibility(View.VISIBLE);
                                }
                                url = ESystem.formatPath(url);
                                imgUrlList.add(url);
                                showImg(url, i, imgUrlList);
                                break;
                        }
                    }
                }
            }
        }

    }


    /**
     * 加载附件中的图片
     *
     * @param optionsDetail
     */
    public void startLoadAttachmentsOnlyImg(OptionDetail optionsDetail, View seekBar) {
        // 取附件集合
        final List<Attachments> attachmentsList = optionsDetail.getAttachments();

        List<String> audioUrlList = new ArrayList<String>();
        if (attachmentsList != null && !attachmentsList.isEmpty()) {
            // 取出所有的图片或语音地址
            List<String> imgUrlList = new ArrayList<String>();
            for (int i = 0; i < attachmentsList.size(); i++) {
                Attachments attachments = attachmentsList.get(i);
                if (attachments != null) {
                    String url = attachments.getUrl();
                    if (!TextUtils.isEmpty(url)) {
                        switch (attachments.getFileType()) {
                            case Attachments.AttachmentFileType.ATTACHMENT_FILE_TYPE_IMG:// 图片
                                imgUrlList.add(ESystem.formatPath(url));
                                break;
                            case Attachments.AttachmentFileType.ATTACHMENT_FILE_TYPE_AUDIO:// 语音
                                audioUrlList.add(ESystem.formatPath(url));
                                break;
                        }
                    }
                }
            }

            if (!imgUrlList.isEmpty()) {

                imgContainerRemoveAllViews();
                for (int i = 0; i < imgUrlList.size(); i++) {
                    if (i == 0) {
                        seekBar.setVisibility(View.GONE);
                        imgContainerSetVisibility(View.VISIBLE);
                    }
                    showImg(imgUrlList.get(i), i, imgUrlList);
                }
            }
        }
    }


    /**
     * 添加填空题答案
     */
    public List<AnswerContent> getBlankAnswer() {

        int len = optionsLayout.getChildCount();
        List<AnswerContent> answerContents = new ArrayList<AnswerContent>();

        for (int i = 0; i < len; i++) {

            View itemView = optionsLayout.getChildAt(i);
            EditText itemText = (EditText) itemView.findViewById(R.id.item_options_tv);

            if (itemText != null) {

                AnswerContent answerContent;
                String answerStr = itemText.getTag().toString().trim();
                answerContent = new AnswerContent();
                answerContent.setSid(i);
                answerContent.setRefAnswer(answerStr);

                if (!TextUtils.isEmpty(itemText.getText())) {

                    String content = itemText.getText().toString().trim();
                    content = content.replaceAll("\\s{1,}", " ");
                    answerContent.setContent(content);

                } else {
                    //未作答
                    answerContent.setContent("");
                }
//                String answerStr = itemText.getTag().toString();
                answerContents.add(answerContent);
            }
        }

        if (answerContents.size() > 0) {
            return answerContents;
        } else {
            return null;
        }
    }


    public void enableBlankInput() {
        int len = optionsLayout.getChildCount();
        for (int i = 0; i < len; i++) {
            View itemView = optionsLayout.getChildAt(i);
            EditText itemText = (EditText) itemView.findViewById(R.id.item_options_tv);
            if (itemText != null) {
//                itemText.setEnabled(false);
                InputMethodManager imm = (InputMethodManager) itemText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
                if (imm != null && imm.isActive()) {
                    imm.hideSoftInputFromWindow(itemText.getApplicationWindowToken(), 0);
                }
            }
        }
    }


    public OptionInfo getChoicOptionInfo() {
        return checkedOptionInfo;
    }

    public void allowAnswer(boolean allowAnswer) {

//        mAllowAnswer = allowAnswer;
        mAllowAnswer = true;
    }


    public void setBigStemHighLight(boolean isStemHighLight) {
        if (isStemHighLight) {
            tvBigStem.setTextColor(getResources().getColor(R.color.black));
            bg_big_stem.setBackgroundColor(getResources().getColor(R.color.white));

            bg_question_content.setBackgroundColor(getResources().getColor(R.color.layer_bg_));
            tvChildStem.setTextColor(getResources().getColor(R.color.light_gray8));
            tvStem.setTextColor(getResources().getColor(R.color.light_gray8));

        } else {
            tvBigStem.setTextColor(getResources().getColor(R.color.light_gray8));
            bg_big_stem.setBackgroundColor(getResources().getColor(R.color.layer_bg_));

            bg_question_content.setBackgroundColor(getResources().getColor(R.color.white));
            tvChildStem.setTextColor(getResources().getColor(R.color.black));
            tvStem.setTextColor(getResources().getColor(R.color.black));
        }


    }


    public String getBigStem() {
        if (TextUtils.isEmpty(tvBigStem.getText())) {
            return "";
        } else {
            return tvBigStem.getText().toString();
        }
    }
}
